package za.org.jcicada.syshealth;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import za.org.jcicada.genss.sensor.ISensor;

public class ColourListCellRenderer extends JLabel implements ListCellRenderer {

	private static final long serialVersionUID = 1L;
	
	private static final Color HIGHLIGHT_COLOR = new Color(0xe8, 0xf2, 0xfe);
	
	public ColourListCellRenderer() {
		setOpaque(true);
	}

	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		ISensor sensor = (ISensor) value;
		setText(sensor.getName());
		setForeground(SensorColourMap.getSensorColor(sensor));
		if (isSelected) {
			setBackground(HIGHLIGHT_COLOR);
		} else {
			setBackground(Color.white);
		}
		return this;
	}

}
